Pollock

frequency=(12:300)*1e3 #frequencies Hz
theta = seq(65,115) #orientations

c.w = 1490 #Ambient water m/s
rho.w = 1026.8 #density ambient water kg/m3

c.fb=1570 #soundspeed body 
c.b=345 #soundspeed swimbladder
cs = c(c.fb, c.b)

rho.fb=1070 #density body kg/m3
rho.b=1.24 #density swimbladder kg/m3
rhos = c(rho.fb, rho.b)

L = c(29.7,24.1,36,34.2,23.9,33.9)/1e2 #Lengths for pollocks in m

XRay 1

img=(jpeg::readJPEG(list.files(path=dd,pattern=".jpg", full.names = T)[1]))
img2=(jpeg::readJPEG(list.files(path=dd,pattern=".jpg", full.names = T)[2]))
par(mfrow=c(1,2))
plot(1:2, type='n')
rasterImage(img,1,1,2,2)
plot(1:2, type='n')
rasterImage(img2,1,1,2,2)      

KRM shape

shp1 = KRMr::Imagej2shp(shp=read.csv(paste0(dd,"/Pollock01.csv")))
KRMr::get_shp3d(shp1)
## 2023-02-23 22:25:18:2 Body parts detected

KRM

ofn = paste0(dd,"/krm1.csv") #output filename
if(file.exists(ofn)==F){
  #Run KRM
  krm1 = krm(frequency = frequency,
      c.w = c.w,
      rho.w = rho.w,
      theta = theta,
      cs =cs,
      rhos = rhos,
      shape = shp1,
      modes = c("fluid","soft"),
      L = L[1],
      fb = 1)
  
  write.csv(krm1,ofn)
}else{krm1 = read.csv(ofn)}

Plot result:

plot_res = function(data=krm1, lims=c(-60,-30)){
  ggplot(data=data, aes(x=frequency/1e3, y=theta, fill=TS))+
    geom_tile()+
    scale_fill_gradientn(colors=rev(pals::brewer.spectral(15)), 
                         limits=lims, oob=scales::squish,
                         name=expression(TS~"(dB re 1"*m^2*")"))+
    scale_x_continuous(expand=c(0,0))+
    scale_y_continuous(expand=c(0,0))+
    ylab(expression(theta~"(°)"))+
    xlab("Frequency (kHz)")+
    theme_classic()+
    theme(legend.position = "bottom",
          text=element_text(size=16),
          legend.key.width = unit(2, 'cm'))
}
plot_res(krm1,c(-60,-30))

XRay 2

img=(jpeg::readJPEG(list.files(path=dd,pattern=".jpg", full.names = T)[3]))
img2=(jpeg::readJPEG(list.files(path=dd,pattern=".jpg", full.names = T)[4]))
par(mfrow=c(1,2))
plot(1:2, type='n')
rasterImage(img,1,1,2,2)
plot(1:2, type='n')
rasterImage(img2,1,1,2,2)      

KRM shape

shp2 = KRMr::Imagej2shp(shp=read.csv(paste0(dd,"/Pollock02.csv")))
KRMr::get_shp3d(shp2)
## 2023-02-23 22:25:28:2 Body parts detected

KRM

ofn = paste0(dd,"/krm2.csv") #output filename
if(file.exists(ofn)==F){
  #Run KRM
  krm2 = krm(frequency = frequency,
      c.w = c.w,
      rho.w = rho.w,
      theta = theta,
      cs =cs,
      rhos = rhos,
      shape = shp1,
      modes = c("fluid","soft"),
      L = L[2],
      fb = 1)
  
  write.csv(krm2,ofn)
}else{krm2 = read.csv(ofn)}

Plot result:

plot_res(krm2,c(-60,-30))

XRay 3

img=(jpeg::readJPEG(list.files(path=dd,pattern=".jpg", full.names = T)[5]))
img2=(jpeg::readJPEG(list.files(path=dd,pattern=".jpg", full.names = T)[6]))
par(mfrow=c(1,2))
plot(1:2, type='n')
rasterImage(img,1,1,2,2)
plot(1:2, type='n')
rasterImage(img2,1,1,2,2)      

KRM shape

shp3 = KRMr::Imagej2shp(shp=read.csv(paste0(dd,"/Pollock03.csv")))
KRMr::get_shp3d(shp3)
## 2023-02-23 22:25:37:2 Body parts detected

KRM

ofn = paste0(dd,"/krm3.csv") #output filename
if(file.exists(ofn)==F){
  #Run KRM
  krm3 = krm(frequency = frequency,
      c.w = c.w,
      rho.w = rho.w,
      theta = theta,
      cs =cs,
      rhos = rhos,
      shape = shp1,
      modes = c("fluid","soft"),
      L = L[3],
      fb = 1)
  
  write.csv(krm3,ofn)
}else{krm3 = read.csv(ofn)}

Plot result:

plot_res(krm3,c(-60,-30))

XRay 4

img=(jpeg::readJPEG(list.files(path=dd,pattern=".jpg", full.names = T)[7]))
img2=(jpeg::readJPEG(list.files(path=dd,pattern=".jpg", full.names = T)[8]))
par(mfrow=c(1,2))
plot(1:2, type='n')
rasterImage(img,1,1,2,2)
plot(1:2, type='n')
rasterImage(img2,1,1,2,2)      

KRM shape

shp4 = KRMr::Imagej2shp(shp=read.csv(paste0(dd,"/Pollock04.csv")))
KRMr::get_shp3d(shp4)
## 2023-02-23 22:25:46:2 Body parts detected

KRM

ofn = paste0(dd,"/krm4.csv") #output filename
if(file.exists(ofn)==F){
  #Run KRM
  krm4 = krm(frequency = frequency,
      c.w = c.w,
      rho.w = rho.w,
      theta = theta,
      cs =cs,
      rhos = rhos,
      shape = shp1,
      modes = c("fluid","soft"),
      L = L[4],
      fb = 1)
  
  write.csv(krm4,ofn)
}else{krm4 = read.csv(ofn)}

Plot result:

plot_res(krm4,c(-60,-30))